import React, { useEffect, useState } from "react";
import moment from "moment";

export default function ClockFun() {
  let [time, setTime] = useState(moment().format("YYYY-MM-DD hh:mm:ss"));

  useEffect(() => {
    let timer = setInterval(() => {
      console.log("aaaaaaa");

      setTime(moment().format("YYYY-MM-DD hh:mm:ss"));
    }, 1000);
    return () => {
      clearInterval(timer);
    };
  });

  return (
    <div>
      <div>现在的时间:</div>
      <h2>{time}</h2>
    </div>
  );
}
